package logic

import (
	"context"
	"shop_srv/shop"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddGoodLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewAddGoodLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddGoodLogic {
	return &AddGoodLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *AddGoodLogic) AddGood(req *types.AddGoodRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	userId := 1
	good, err := l.svcCtx.ShopRpc.AddGood(l.ctx, &shop.AddGoodRequest{
		GoodTitle: req.GoodTitle,
		GoodStock: int64(req.GoodStock),
		GoodNum:   int64(req.GoodNum),
		GoodPrice: float32(req.GoodPrice),
		UserId:    int64(userId),
	})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "添加成功",
		Code: 500,
		Data: good,
	}, nil
}
